package codepulse.blogmoon.cn.common.context;

import com.alibaba.ttl.TransmittableThreadLocal;
import lombok.Data;

@Data
public class Context {

    private static final long serialVersionUID = -3395618317964633994L;

    private static TransmittableThreadLocal<Context> LOCAL = new TransmittableThreadLocal<Context>() {
        @Override
        protected Context initialValue() {
            return new Context();
        }
    };

    private Long bizAcctId;

    private String acctName;

    private Long teamId;

    private Integer versionCode;


    public static Context get() {
        return LOCAL.get();
    }

    public static void remove() {
        LOCAL.remove();
    }

    public static Context removeAndSet() {
        remove();
        return set();
    }


    public static Context set() {
        Context ict = Context.get();
        if (ict == null) {
            return null;
        }
        return ict;
    }

}
